﻿<?php
	session_start();
	error_reporting (E_ALL ^ E_NOTICE);
	include("./config/conn_database.php");
	if($_SESSION["mem_pid"] != "" || $_SESSION["mem_pid"] != NULL){
		if($_GET['act']=="del"){
			$strSQL = "DELETE FROM add_activity WHERE act_id = '".$_GET['id']."'";
			$objQuery = mysql_query($strSQL);
			echo "<meta http-equiv='refresh' content='0; url=edit_index_activity.php'>";
		}else if($_GET['act']=="edit"){
			echo "<meta http-equiv='refresh' content='0; url=edit_index_activity.php?id=".$_GET['id']."'>";
		}else if($_GET['act']=="edit_sql"){
			if(trim($_FILES["fileUpload"]["tmp_name"]) != ""){
				$images = $_FILES["fileUpload"]["tmp_name"];
				$new_images = "activity_".$_FILES["fileUpload"]["name"];
				$strDate = $_POST['stryy'].$_POST['strmm'].$_POST['strdd'];
				echo $strSQL = "UPDATE add_activity SET
									act_topic = '".$_POST['topic']."',
									act_plot =  '".$_POST['plot']."',
									act_detail =  '".$_POST['detail']."',
									act_image =  '".$new_images."',
									act_ref =  '".$_POST['ref']."',
									act_date =  '".date("Ymd")."',
									act_date_end =  '".$strDate."',
									mem_pid =  '".$_SESSION["mem_pid"]."'
									WHERE  act_id = '".$_GET['id']."'";						
					$objQuery = mysql_query($strSQL);
					copy($_FILES["fileUpload"]["tmp_name"],"./images/act_news/".$new_images);
			}
			echo "<meta http-equiv='refresh' content='0; url=edit_index_activity.php'>";
		}else{
			if(trim($_FILES["fileUpload"]["tmp_name"]) != ""){
				$images = $_FILES["fileUpload"]["tmp_name"];
				$new_images = "activity_".$_FILES["fileUpload"]["name"];
				$strDate = $_POST['stryy'].$_POST['strmm'].$_POST['strdd'];
				$strSQL = "INSERT INTO add_activity (act_id, act_topic, act_plot, act_detail, act_image, act_ref, act_date, act_date_end, mem_pid) 
								VALUES (NULL, '".$_POST['topic']."', '".$_POST['plot']."', '".$_POST['detail']."', '".$new_images."', '".$_POST['ref']."', '".date("Ymd")."', '".$strDate."', '".$_SESSION["mem_pid"]."');";
				$objQuery = mysql_query($strSQL);
				copy($_FILES["fileUpload"]["tmp_name"],"./images/act_news/".$new_images);
			}
			if($objQuery){
				echo "<script type='text/javascript'>";
				echo "alert('บันทึกข้อมูลสำเร็จ')";
				echo "</script>";
				echo "<meta http-equiv='refresh' content='0; url=edit_index_activity.php'>";
			}else{
				echo "<script type='text/javascript'>";
				echo "alert('บันทึกข้อมูลไม่สำเร็จ : ติดต่อผู้ดูแลระบบ')";
				echo "</script>";
				echo "<meta http-equiv='refresh' content='0; url=edit_index_activity.php'>";
			}
		}
		mysql_close($objConnect);
	}else{	
		echo "<script type='text/javascript'>";
		echo "alert('กรุณาเข้าสู่ระบบก่อนเข้าใช้งาน')";
		echo "</script>";
		echo "<meta http-equiv='refresh' content='0; url=index.php'>";
	}
?>
